package lesson2.api.helpers;

import lesson2.api.ApplicationManager;
import lesson2.pages.IndexPage;
import lesson2.pages.RegistrationPage;

import org.openqa.selenium.By;

public class PageHelper
{
	ApplicationManager app;

	IndexPage indexPage;
	RegistrationPage registrationPage;

	public PageHelper(ApplicationManager p_app)
	{
		app = p_app;
	}

	public IndexPage indexPage()
	{
		if (indexPage == null)
		{
			indexPage = new IndexPage(app);
		}
		return indexPage;
	}

	public RegistrationPage registrationPage()
	{
		if (registrationPage == null)
		{
			registrationPage = new RegistrationPage(app);
		}
		return registrationPage;
	}

	public boolean isLoggedIn()
	{
		boolean isLoggedIn = app.webElementHelper().isElementPresent(By.cssSelector("a.logout"));
		return isLoggedIn;
	}

	public void logout()
	{
		if (isLoggedIn())
		{
			app.webElementHelper().click(By.cssSelector("a.logout"));
		}
	}

	public boolean isRegistered()
	{
		boolean isRegistered = app.webElementHelper().isElementPresent(By.id("flash_notice"));
		return isRegistered;
	}
}
